<?php

use Phinx\Db\Adapter\MysqlAdapter;
use think\migration\Migrator;
use think\migration\db\Column;

class CreateTableAdmin extends Migrator
{
    public function up()
    {
        if (!$this->hasTable('admin')) {
            $table = $this->table('admin', ['engine' => 'InnoDB'])
                ->setId('id')
                ->setPrimaryKey('id')
                ->setComment('管理员表');
            $table->addColumn('username', 'string', ['limit' => 30, 'null' => false, 'comment' => '账号'])
                ->addColumn('password', 'string', ['limit' => 50, 'null' => false, 'default' => '', 'comment' => '密码'])
                ->addColumn('nickname', 'string', ['limit' => 50, 'null' => false, 'default' => '', 'comment' => '昵称'])
                ->addColumn('img', 'string', ['limit' => 255, 'null' => false, 'default' => '', 'comment' => '头像'])
                ->addColumn('add_time', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '注册时间'])
                ->addColumn('low_login_time', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '最后登录时间'])
                ->addColumn('is_on_line', 'integer', ['limit' => MysqlAdapter::INT_TINY, 'null' => false, 'default' => '0', 'comment' => '0-不在线 1-在线'])
                ->addColumn('delete_time', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '删除时间'])
                ->addColumn('role_id', 'integer', ['limit' => 11, 'null' => false, 'default' => '0', 'comment' => '角色id'])
                ->create();
        }
    }

    public function down()
    {
        if ($this->hasTable('admin')) {
            $this->dropTable('admin');
        }
    }
}
